<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button class="btn1">点击我存cookie</button>
    <button class="btn2">点击我获取cookie</button>

    <script>
      let btn1 = document.querySelector(".btn1");
      let btn2 = document.querySelector(".btn2");
      // 设置cookie,设置的时候可以手动修改path路径，如果不更改默认就是当前路径
      btn1.onclick = function () {
        document.cookie='girl=yuzhouzhou;path=/'
      };
      // 获取cookie，路径需要和存储的时候一样，或者比存的路径要小，一般来说设置/比较好
      btn2.onclick = function () {
        console.log(document.cookie)
      };
    </script>
  </body>
</html>
